<%@ page import="java.text.SimpleDateFormat"%>
<%@	page import ="java.util.ArrayList" %>
<%@	page import ="java.util.Iterator" %>
<%@	page import ="java.util.List" %>

<%@	page import ="com.adisi.objetos.Alerta" %>
<%@	page import ="com.adisi.objetos.Chofer" %>
<%@	page import ="com.adisi.objetos.Auto" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
<jsp:directive.include file="headerComun.jsp" />
<body>
<div class="container">
	<jsp:directive.include file="menuNavegacion.jsp" />
	
		<script type="text/javascript">
		
		$(document).ready(function(){	
			<% 
			
				ArrayList<Alerta> alertaz = new ArrayList<Alerta>();
			
				String titulo = null;
				String msg = (String)request.getAttribute("msg");
				String msgType = (String)request.getAttribute("msg_type");
				try {
					titulo = (String)request.getAttribute("titulo");
				}
				catch(NullPointerException e) {
					
				}
				finally {
					if(titulo==null)
						titulo = "Alertas";
				}
				
				if(msgType==null) msgType = "default";
				if(msg!=null) { 
			%>
					$('#alert_placeholder').append('<div class="alert alert-<%=msgType %> fade in"><button type="button" class="close" data-dismiss="alert">&times;</button><%=msg%></div>');
			    	alertTimeout(3000);
			<% } %>
			


			
		});		
		
	    </script>
	    	
	<div class="row clearfix">
		<div class="col-md-8 column">
			<h3>Gesti&oacute;n de <%= titulo%></h3>
		</div>
		<div class="col-md-4 column">
			<form class="navbar-right form-inline" role="login" action="#">
				<div class="form-group">
					<label class="sr-only" for="Search">Buscar</label>
					<input type="text" class="form-control" id="Search" placeholder="Introduce criterio de b&uacute;squeda" >
				</div>
				<button type="button" class="btn btn-default" title="Buscar">
					<span class="glyphicon glyphicon-search"></span>
				</button>				
			</form>			
		</div>
	</div>
	<div class="row clearfix">
		<div class="col-md-12 column">
			<div class="table-responsive">
			<%
				
				try {
					alertaz = (ArrayList<Alerta>)request.getAttribute("alertas");					
				}
				catch(NullPointerException e) {	
			%>
					<script type="text/javascript">
					$(document).ready(function(){
						$('#alert_placeholder').after('<div class="alert alert-danger fade in">No se recibieron los par&aacute;metros requeridos.</div>');
					});	
				    </script>
			<%	
				}; 
			%>
				<table class="table table-striped table-bordered table-hover">
					<thead>
					    <tr>
					    	<th>Afectado</th>
							<th>Tipo</th>
							<th>Motivo</th>
							<th>L&iacute;mite</th>
							<th style="min-width:220px">Acciones
								<% if(Seguridad.validarUsuarioProceso(usuario, "AltaAlerta")) { %>
								<div class="btn-group pull-right btn-group-sm">
									<a type="button" class="btn btn-default " title="Agregar datos" href="alerta?ad">
										<span class="glyphicon glyphicon-plus" style="color:green"></span>
									</a>
								</div>
								<% } %>
							</th>
						</tr>
					</thead>
					<tbody>
<%
						for(int i = 0; i < alertaz.size(); i++) {
							Alerta alerta = alertaz.get(i);
							int pid = alerta.getIdAlerta();
							
					%>
						<tr>
							<td>
							<% 
								Chofer chofer;
								Auto auto;
								
								if(alerta.getObjeto().equals("Chofer")) {
									try {
									chofer = (Chofer)alerta.getObj();
								
									out.print("Chofer&nbsp;:&nbsp;");
									out.print(chofer.getNombreCompleto());
									}
									catch(Exception e) {
										out.print(e.getMessage());
									}
								} else if(alerta.getObjeto().equals("Auto")) {
									auto = (Auto)alerta.getObj();
								
									out.print("Auto&nbsp;:&nbsp;");
									out.print(auto.getMarcaAuto()+" "+auto.getDominioAuto());
								} 
							%>
							</td>
							<td><%= alerta.getTipoAlerta()=='F'?"Fecha":"Kms" %></td>
							<td><%= alerta.getMotivoAlerta() %></td>
							<td><%= alerta.getTipoAlerta()=='F'?new SimpleDateFormat("d/M/yyyy").format(alerta.getFechaAlerta()):alerta.getKmAlerta().toString()+" kms"%></td>
							<td>
								<div class="btn-group ">
									<% if(Seguridad.validarUsuarioProceso(usuario, "ModificaAlerta")) { %>
									<a type="button" class="btn btn-default" title="Modificar datos" href="alerta?ed=<%= pid %>">
										<span class="glyphicon glyphicon-edit"></span>
									</a>									
									<%} %>
									<a type="button" class="btn btn-default" title="Imprimir datos" href="alerta?pr=<%= pid %>">
										<span class="glyphicon glyphicon-print"></span>
									</a>
									<% if(Seguridad.validarUsuarioProceso(usuario, "BajaAlerta")) { %>
									<a type="button" class="confirm btn btn-default" title="Eliminar" href="#" hrefcc="alerta?bor=<%= pid %>"  >
										<span class="glyphicon glyphicon-trash"></span>
									</a>										
									<%} %>
								</div>							
							</td>
						</tr>
					<% } %>					
						
					</tbody>				
				</table>
			</div>
		</div>
	</div>
</div>

</body>
</html>